/*
 * @Author: hmhvictory 1400628624@qq.com
 * @Date: 2025-07-31 20:14:18
 * @LastEditors: hmhvictory 1400628624@qq.com
 * @LastEditTime: 2025-07-31 20:14:27
 * @FilePath: \Gitee实训笔记\day14\HomeWork\Test02\Duration.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day14.HomeWork.Test02;

public class Duration {
  private int hours;
    private int minutes;
    private int seconds;

    // 三参构造器
    public Duration(int hours, int minutes, int seconds) {
        this.hours = hours;
        this.minutes = minutes;
        this.seconds = seconds;
    }

    // 一参构造器
    public Duration(int totalSeconds) {
        this.hours = totalSeconds / 3600;
        totalSeconds %= 3600;
        this.minutes = totalSeconds / 60;
        this.seconds = totalSeconds % 60;
    }

    // 获取小时数
    public int getHours() {
        return hours;
    }

    // 获取分钟数
    public int getMinutes() {
        return minutes;
    }

    // 获取秒数
    public int getSeconds() {
        return seconds;
    }

    // 获取总秒数
    public int getTotalSeconds() {
        return hours * 3600 + minutes * 60 + seconds;
    }

    // 重写 toString 方法
    @Override
    public String toString() {
        return hours + ":" + minutes + ":" + seconds;
    }
}
